package com.winner.data.exception;

import java.util.HashMap;

/**
 * 返回结果Map
 *
 * @author wangxinle5
 * @since 2022-09-20
 */
public class R extends HashMap<String, Object> {

    public static R success(Object obj) {
        R hm = success();
        hm.put("data", obj);
        return hm;

    }

    public static R success() {
        R hm = new R();
        hm.put("code", BusinessEnum.SUCCESS.getCode());
        hm.put("message", BusinessEnum.SUCCESS.getMessage());
        return hm;
    }

    public static R error(BusinessEnum exceptionEnum) {
        R hm = new R();
        hm.put("code", exceptionEnum.getCode());
        hm.put("message", exceptionEnum.getMessage());
        return hm;
    }

    public static R error(BusinessEnum exceptionEnum, Object data) {
        R hm = error(exceptionEnum);
        hm.put("data", data);
        return hm;
    }

    public static R error(Object obj) {
        R hm = new R();
        hm.put("code", BusinessEnum.FAIL.getCode());
        hm.put("message", obj);
        return hm;
    }

}
